const moment = require('moment');
const flowerList = require('../utils/flower').flowerType;
module.exports = function(req, res, next){
    res.locals.timeFormat = function(str){
        const time = moment(str).format('YYYY年MM月DD日 H:mm');
        return time;
    }
    res.locals.getFlowerType = function(type, category){
        let result = '';
        let arr = [];
        if(!category){
            flowerList.map((value) => {
                if(type == value.type){
                    result = value.name;
                }
            })
        }else{
            flowerList.map((value) => {
                if(type == value.type){
                    arr = value.category;
                }
            })
            arr.map((value)=>{
                if(category == value.id){
                    result = value.name;
                }
            });
        }
        return result;
    }
    next();
}